#include <stdlib.h>

#include <cm/file/config_file.h>
#include <cm/cm_str.h>
#include <stdio.h>
#include <string.h>

int main() {
	cfg_t *cfile = cfg_open("./config.ini", 8);
	if (cfile != NULL ) {
		cfg_addvalue(cfile, "SEC1", "ABC", "DEF");
		cfg_addvalue(cfile, "SEC1", "hel lo", "world");
		cfg_addvalue(cfile, "SEC1", "happy", "do g");
		cfg_addvalue(cfile, "SEC1", "n	in", "hao");
		cfg_addvalue(cfile, "SEC2", "zhang san", "li si");
		cfg_addvalue(cfile, "SEC2", "", "");
		cfg_addvalue(cfile, "SEC1", NULL, NULL );
		cfg_addvalue(cfile, "SEC1", NULL, "none");
		cfg_addvalue(cfile, "SEC1", "CDEF", NULL );

		cfg_flush(cfile);
		cfg_printf(cfile);

		char buf[LEN_MAX_ITEM_NAME];
		memset(buf, 0, LEN_MAX_ITEM_NAME);
		if (cfg_getvalue(cfile, "SECTION1", "KEY1", buf, LEN_MAX_ITEM_NAME)
				== 0)
			printf("KEY1 = %s\n", buf);
		if (cfg_getvalue(cfile, "SEC1", "happy", buf, LEN_MAX_ITEM_NAME) == 0)
			printf("happy = %s\n", buf);

		if (cfg_getvalue(cfile, "SEC2", "zhangsan", buf, LEN_MAX_ITEM_NAME)
				== 0)
			printf("zhangsan = %s\n", buf);
		if (cfg_getvalue(cfile, "SEC2", "zhang san", buf, LEN_MAX_ITEM_NAME)
				== 0)
			printf("zhang san = %s\n", buf);

		cfg_close(&cfile);
	}

	char str1[] = "      hello	, world!	";
	char str2[] = "      hello	, world!	";
	char str3[] = "      hello	, world!    ";

	printf("strip head: %d(%s)\n", strlen(str1), str_strip_head(str1));
	printf("strip tail: %d(%s)\n", strlen(str2), str_strip_tail(str2));
	printf("strip all : %d(%s)\n", strlen(str3), str_strip_all(str3));

	int a = 10;
	int b = 20;
	printf("a = %d, b = %d, sum = %d\n", ++a + b, ++b + a, a + b);

	exit(0);
}
